﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using EFEntity;
using ISerives;
using Microsoft.EntityFrameworkCore;
using Model;

namespace Serives
{
    public class salary_standard_details_Serives : Isalary_standard_details_Serives
    {
        private readonly MyDbContext myDbContext;
        private readonly IMapper mapper;

        public salary_standard_details_Serives(MyDbContext myDbContext,IMapper mapper)
        {
            this.myDbContext = myDbContext;
            this.mapper = mapper;
        }
        public async Task<int> Add(Esalary_standard_details ssd)
        {
            myDbContext.Essd.Add(ssd);
            return await myDbContext.SaveChangesAsync();
        }

        public async Task<int> Del(Esalary_standard_details ssd)
        {

            myDbContext.Remove(myDbContext.Essd.Where(e => e.standard_id == ssd.standard_id).FirstOrDefault());
            return await myDbContext.SaveChangesAsync();
        }

        public async Task<Esalary_standard_details> Select(string standard_id, int pbc_id)
        {
            Esalary_standard_details list = new Esalary_standard_details();
            await Task.Run(() =>
            {
                list = myDbContext.Essd.Where(e => e.standard_id == standard_id && e.item_id == pbc_id).FirstOrDefault();

            });
            return list;
        }

        public async Task<List<salary_standard_details>> SelectId(string id)
        {
            List<salary_standard_details> list = new List<salary_standard_details>();
           await Task.Run(()=>{ 
            List<Esalary_standard_details> list2=myDbContext.Essd.Where(e => e.standard_id == id).ToList();
               list = mapper.Map<List<salary_standard_details>>(list2);
           });
            return list;
        }
    }
}
